package cn.tedu.flower.manage.Express.controller;

import cn.tedu.flower.manage.Express.entity.Express;
import cn.tedu.flower.manage.Express.service.ExpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/express")
public class ExpressController {

    private ExpressService expressService;

    @Autowired
    public ExpressController(ExpressService expressService) {
        this.expressService = expressService;
    }

    @GetMapping("/")
    public List<Express> getAllExpress() {
        return expressService.getAllExpress();
    }

    @GetMapping("/{id}")
    public Express getExpressById(@PathVariable int id) {
        return expressService.getExpressById(id);
    }

    @PostMapping("/")
    public void addExpress(@RequestBody Express express) {
        expressService.addExpress(express);
    }

    @PutMapping("/{id}")
    public void updateExpress(@PathVariable int id, @RequestBody Express express) {
        express.setId(id);
        expressService.updateExpress(express);
    }

    @DeleteMapping("/{id}")
    public void deleteExpress(@PathVariable int id) {
        expressService.deleteExpress(id);
    }
}
